﻿//********************************************************************************//
//创建日期：<创建日期，2010-08-02>
//创建作者：<王一飞，wangyifei@shanghai3h.com>
//功能说明：YS_ZW_FAPIAOKC实体层次
//********************************************************************************//

#region Entity

using System;
using System.Data;
using Entity;
using Oracle.DataAccess.Client;
using Platform.Configuration;
using Platform.Data;

namespace Entity
{
    [Serializable]
    public class YS_ZW_FAPIAOKC
    {
        private decimal? m_dec_i_jlzt;

        private decimal? m_dec_i_lingyongsl;

        private decimal? m_dec_i_shengyusl;

        private decimal? m_dec_i_shuliang;

        private decimal? m_dec_i_type;

        private decimal? m_dec_i_yuanhaoduanid;

        private decimal m_dec_id;

        private DateTime? m_DT_d_rukurq;

        private string m_str_s_dangqianqshm;

        private string m_str_s_jieshuhm;

        private string m_str_s_miaoshu;

        private string m_str_s_qishihm;

        private string m_str_s_rukur;

        /// <summary>
        ///     主键
        /// </summary>
        public decimal ID
        {
            get { return m_dec_id; }
            set { m_dec_id = value; }
        }

        /// <summary>
        ///     起始号码
        /// </summary>
        public string S_QISHIHM
        {
            get { return m_str_s_qishihm; }
            set { m_str_s_qishihm = value; }
        }

        /// <summary>
        ///     结束号码
        /// </summary>
        public string S_JIESHUHM
        {
            get { return m_str_s_jieshuhm; }
            set { m_str_s_jieshuhm = value; }
        }

        /// <summary>
        ///     数量
        /// </summary>
        public decimal? I_SHULIANG
        {
            get { return m_dec_i_shuliang; }
            set { m_dec_i_shuliang = value; }
        }

        /// <summary>
        ///     当前起始号码
        /// </summary>
        public string S_DANGQIANQSHM
        {
            get { return m_str_s_dangqianqshm; }
            set { m_str_s_dangqianqshm = value; }
        }

        /// <summary>
        ///     剩余数量
        /// </summary>
        public decimal? I_SHENGYUSL
        {
            get { return m_dec_i_shengyusl; }
            set { m_dec_i_shengyusl = value; }
        }

        /// <summary>
        ///     0 正常 -1 删除
        /// </summary>
        public decimal? I_JLZT
        {
            get { return m_dec_i_jlzt; }
            set { m_dec_i_jlzt = value; }
        }

        /// <summary>
        ///     已领用数量
        /// </summary>
        public decimal? I_LINGYONGSL
        {
            get { return m_dec_i_lingyongsl; }
            set { m_dec_i_lingyongsl = value; }
        }

        /// <summary>
        ///     入库人
        /// </summary>
        public string S_RUKUR
        {
            get { return m_str_s_rukur; }
            set { m_str_s_rukur = value; }
        }

        /// <summary>
        ///     入库时间
        /// </summary>
        public DateTime? D_RUKURQ
        {
            get { return m_DT_d_rukurq; }
            set { m_DT_d_rukurq = value; }
        }

        /// <summary>
        ///     0 正常入库 1取消领用生成
        /// </summary>
        public decimal? I_TYPE
        {
            get { return m_dec_i_type; }
            set { m_dec_i_type = value; }
        }

        /// <summary>
        ///     说明
        /// </summary>
        public string S_MIAOSHU
        {
            get { return m_str_s_miaoshu; }
            set { m_str_s_miaoshu = value; }
        }

        /// <summary>
        ///     所属原发票号码段ID(一般用于取消领用等生成的新记录)
        /// </summary>
        public decimal? I_YUANHAODUANID
        {
            get { return m_dec_i_yuanhaoduanid; }
            set { m_dec_i_yuanhaoduanid = value; }
        }
    }
}

#endregion

#region EntityProcess

namespace BLL.Access
{
    //using System.Data.OracleClient;

    public class YS_ZW_FAPIAOKCProcess
    {
        #region Field

        protected string conn;

        #endregion

        #region Construction

        public YS_ZW_FAPIAOKCProcess()
        {
            conn = ConfigHelper.PlatformConnString;
        }

        #endregion

        #region public

        /// <summary>
        ///     根据YS_ZW_FAPIAOKC实体添加或者修改YS_ZW_FAPIAOKC信息
        /// </summary>
        public bool InsertOrUpdate(YS_ZW_FAPIAOKC YS_ZW_FAPIAOKC, OracleTransaction Transaction)
        {
            if (YS_ZW_FAPIAOKC.ID == 0)
                InsertYS_ZW_FAPIAOKC(YS_ZW_FAPIAOKC, Transaction);
            else
                UpdateYS_ZW_FAPIAOKC(YS_ZW_FAPIAOKC, Transaction);
            return YS_ZW_FAPIAOKC.ID == 0 ? false : true;
        }

        /// <summary>
        ///     根据YS_ZW_FAPIAOKC实体添加或修改YS_ZW_FAPIAOKC信息
        /// </summary>
        public bool InsertOrUpdate(YS_ZW_FAPIAOKC YS_ZW_FAPIAOKC)
        {
            return InsertOrUpdate(YS_ZW_FAPIAOKC, null);
        }


        /// <summary>
        ///     根据YS_ZW_FAPIAOKC主键删除YS_ZW_FAPIAOKC信息
        /// </summary>
        /// <param name="ID"></param>
        public bool DeleteYS_ZW_FAPIAOKC(decimal ID, OracleTransaction Transaction)
        {
            var spName = "CS_DelYS_ZW_FAPIAOKC";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = ID;
            var result = 0;
            if (Transaction == null)
                result = OracleHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                result = OracleHelper.ExecuteNonQuery(Transaction, CommandType.StoredProcedure, spName, storedParams);
            return result == 0 ? false : true;
        }

        /// <summary>
        ///     根据YS_ZW_FAPIAOKC主键删除YS_ZW_FAPIAOKC信息
        /// </summary>
        /// <param name="ID"></param>
        public bool DeleteYS_ZW_FAPIAOKC(decimal ID)
        {
            return DeleteYS_ZW_FAPIAOKC(ID, null);
        }

        /// <summary>
        ///     根据条件删除YS_ZW_FAPIAOKC信息
        /// </summary>
        /// <param name="WhereClause">条件子句(Oracle语句)不带where</param>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>如果删除成功，返回true,否则返回fals</returns>
        public bool DeleteYS_ZW_FAPIAOKCsDynamic(string WhereClause, OracleTransaction Transaction)
        {
            var spName = "CS_DelYS_ZW_FAPIAOKCsDyn";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = WhereClause;
            var result = 0;
            if (Transaction == null)
                result = OracleHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                result = OracleHelper.ExecuteNonQuery(Transaction, CommandType.StoredProcedure, spName, storedParams);
            return result == 0 ? false : true;
        }

        /// <summary>
        ///     根据条件删除YS_ZW_FAPIAOKC信息
        /// </summary>
        /// <param name="WhereClause">条件子句(Oracle语句)不带where</param>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>如果删除成功，返回true,否则返回fals</returns>
        public bool DeleteYS_ZW_FAPIAOKCsDynamic(string WhereClause)
        {
            return DeleteYS_ZW_FAPIAOKCsDynamic(WhereClause, null);
        }

        /// <summary>
        ///     根据YS_ZW_FAPIAOKC主键选择YS_ZW_FAPIAOKC信息
        /// </summary>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>YS_ZW_FAPIAOKC信息</returns>
        public YS_ZW_FAPIAOKC SelectYS_ZW_FAPIAOKC(decimal ID, OracleTransaction Transaction)
        {
            var spName = "CS_SelYS_ZW_FAPIAOKC";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = ID;
            OracleDataReader rd;
            if (Transaction == null)
                rd = OracleHelper.ExecuteReader(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                rd = OracleHelper.ExecuteReader(Transaction, CommandType.StoredProcedure, spName, storedParams);
            if (rd.Read())
            {
                var YS_ZW_FAPIAOKC = PopulateYS_ZW_FAPIAOKC(rd);
                rd.Close();
                return YS_ZW_FAPIAOKC;
            }
            return null;
        }

        /// <summary>
        ///     根据YS_ZW_FAPIAOKC主键选择YS_ZW_FAPIAOKC信息
        /// </summary>
        /// <returns>YS_ZW_FAPIAOKC信息</returns>
        public YS_ZW_FAPIAOKC SelectYS_ZW_FAPIAOKC(decimal ID)
        {
            return SelectYS_ZW_FAPIAOKC(ID, null);
        }

        /// <summary>
        ///     选择所有YS_ZW_FAPIAOKC信息
        /// </summary>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>所有YS_ZW_FAPIAOKC信息</returns>
        public DataTable SelectYS_ZW_FAPIAOKCsAll(OracleTransaction Transaction)
        {
            var spName = "CS_SelYS_ZW_FAPIAOKCsAll";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            DataSet ds = null;
            if (Transaction == null)
                ds = OracleHelper.ExecuteDataset(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                ds = OracleHelper.ExecuteDataset(Transaction, CommandType.StoredProcedure, spName, storedParams);
            if (ds != null && ds.Tables.Count > 0)
            {
                AddRowNumber(ds.Tables[0]);
                return ds.Tables[0];
            }
            return null;
        }

        /// <summary>
        ///     选择所有YS_ZW_FAPIAOKC信息
        /// </summary>
        /// <returns>所有YS_ZW_FAPIAOKC信息</returns>
        public DataTable SelectYS_ZW_FAPIAOKCsAll()
        {
            return SelectYS_ZW_FAPIAOKCsAll(null);
        }

        /// <summary>
        ///     根据条件选择YS_ZW_FAPIAOKC信息
        /// </summary>
        /// <param name="WhereClause">条件子句(不带where)</param>
        /// <param name="OrderByExpression">排序子句</param>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>YS_ZW_FAPIAOKC信息</returns>
        public DataTable SelectYS_ZW_FAPIAOKCsDynamic(string WhereClause, string OrderByExpression,
            OracleTransaction Transaction)
        {
            var spName = "CS_SelYS_ZW_FAPIAOKCsDyn";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = string.IsNullOrEmpty(WhereClause.Trim()) ? "1=1" : WhereClause;
            storedParams[1].Value = OrderByExpression;
            DataSet ds = null;
            if (Transaction == null)
                ds = OracleHelper.ExecuteDataset(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                ds = OracleHelper.ExecuteDataset(Transaction, CommandType.StoredProcedure, spName, storedParams);
            if (ds != null && ds.Tables.Count > 0)
            {
                AddRowNumber(ds.Tables[0]);
                return ds.Tables[0];
            }
            return null;
        }


        /// <summary>
        ///     根据条件选择YS_ZW_FAPIAOKC信息
        /// </summary>
        /// <param name="WhereClause">条件子句(不带where)</param>
        /// <param name="OrderByExpression">排序子句</param>
        /// <returns>YS_ZW_FAPIAOKC信息</returns>
        public DataTable SelectYS_ZW_FAPIAOKCsDynamic(string WhereClause, string OrderByExpression)
        {
            return SelectYS_ZW_FAPIAOKCsDynamic(WhereClause, OrderByExpression, null);
        }


        /// <summary>
        ///     根据条件选择YS_ZW_FAPIAOKC信息
        /// </summary>
        /// <param name="WhereClause">条件子句(不带where)</param>
        /// <param name="OrderByExpression">排序子句</param>
        /// <param name="PageIndex">页码</param>
        /// <param name="PageSize">页数</param>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>YS_ZW_FAPIAOKC信息</returns>
        public DataTable SelectYS_ZW_FAPIAOKCsDynamic(string WhereClause, string OrderByExpression, int PageIndex,
            int PageSize, OracleTransaction Transaction)
        {
            var spName = "CS_SelYS_ZW_FAPIAOKCsDynPaged";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = string.IsNullOrEmpty(WhereClause.Trim()) ? "1=1" : WhereClause;
            storedParams[1].Value = OrderByExpression;
            storedParams[2].Value = PageIndex;
            storedParams[3].Value = PageSize;
            DataSet ds = null;
            if (Transaction == null)
                ds = OracleHelper.ExecuteDataset(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                ds = OracleHelper.ExecuteDataset(Transaction, CommandType.StoredProcedure, spName, storedParams);
            if (ds != null && ds.Tables.Count > 0)
            {
                AddRowNumber(ds.Tables[0]);
                return ds.Tables[0];
            }
            return null;
        }


        /// <summary>
        ///     根据条件选择YS_ZW_FAPIAOKC信息
        /// </summary>
        /// <param name="WhereClause">条件子句(不带where)</param>
        /// <param name="OrderByExpression">排序子句</param>
        /// <param name="PageIndex">页码</param>
        /// <param name="PageSize">页数</param>
        /// <returns>YS_ZW_FAPIAOKC信息</returns>
        public DataTable SelectYS_ZW_FAPIAOKCsDynamic(string WhereClause, string OrderByExpression, int PageIndex,
            int PageSize)
        {
            return SelectYS_ZW_FAPIAOKCsDynamic(WhereClause, OrderByExpression, PageIndex, PageSize, null);
        }

        /// <summary>
        ///     根据条件更新YS_ZW_FAPIAOKC字段
        /// </summary>
        /// <returns>受影响行数</returns>
        public int UpdateYS_ZW_FAPIAOKCsDynamic(string UpdateValue, string WhereClause, OracleTransaction Transaction)
        {
            var result = 0;
            if (UpdateValue == "" || WhereClause == "")
                return 0;
            var spName = "CS_UpdYS_ZW_FAPIAOKCDyn";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            DataSet ds = null;
            storedParams[0].Value = UpdateValue;
            storedParams[1].Value = WhereClause;
            if (Transaction == null)
                ds = OracleHelper.ExecuteDataset(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                ds = OracleHelper.ExecuteDataset(Transaction, CommandType.StoredProcedure, spName, storedParams);
            result = Convert.ToInt32(storedParams[2].Value);
            return result;
        }

        /// <summary>
        ///     根据条件更新YS_ZW_FAPIAOKC字段
        /// </summary>
        /// <returns>受影响行数</returns>
        public int UpdateYS_ZW_FAPIAOKCsDynamic(string UpdateValue, string WhereClause)
        {
            return UpdateYS_ZW_FAPIAOKCsDynamic(UpdateValue, WhereClause, null);
        }

        #endregion

        #region Private

        private int InsertYS_ZW_FAPIAOKC(YS_ZW_FAPIAOKC YS_ZW_FAPIAOKC, OracleTransaction Transaction)
        {
            var spName = "CS_InsYS_ZW_FAPIAOKC";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = YS_ZW_FAPIAOKC.S_QISHIHM;
            storedParams[1].Value = YS_ZW_FAPIAOKC.S_JIESHUHM;
            storedParams[2].Value = YS_ZW_FAPIAOKC.I_SHULIANG;
            storedParams[3].Value = YS_ZW_FAPIAOKC.S_DANGQIANQSHM;
            storedParams[4].Value = YS_ZW_FAPIAOKC.I_SHENGYUSL;
            storedParams[5].Value = YS_ZW_FAPIAOKC.I_JLZT;
            storedParams[6].Value = YS_ZW_FAPIAOKC.I_LINGYONGSL;
            storedParams[7].Value = YS_ZW_FAPIAOKC.S_RUKUR;
            storedParams[8].Value = YS_ZW_FAPIAOKC.D_RUKURQ;
            storedParams[9].Value = YS_ZW_FAPIAOKC.I_TYPE;
            storedParams[10].Value = YS_ZW_FAPIAOKC.S_MIAOSHU;
            storedParams[11].Value = YS_ZW_FAPIAOKC.I_YUANHAODUANID;
            var result = 0;
            if (Transaction == null)
                result = OracleHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                result = OracleHelper.ExecuteNonQuery(Transaction, CommandType.StoredProcedure, spName, storedParams);
            YS_ZW_FAPIAOKC.ID = Convert.ToInt32(storedParams[12].Value);
            return result;
        }

        private bool UpdateYS_ZW_FAPIAOKC(YS_ZW_FAPIAOKC YS_ZW_FAPIAOKC, OracleTransaction Transaction)
        {
            var spName = "CS_UpdYS_ZW_FAPIAOKC";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = YS_ZW_FAPIAOKC.S_QISHIHM;
            storedParams[1].Value = YS_ZW_FAPIAOKC.S_JIESHUHM;
            storedParams[2].Value = YS_ZW_FAPIAOKC.I_SHULIANG;
            storedParams[3].Value = YS_ZW_FAPIAOKC.S_DANGQIANQSHM;
            storedParams[4].Value = YS_ZW_FAPIAOKC.I_SHENGYUSL;
            storedParams[5].Value = YS_ZW_FAPIAOKC.I_JLZT;
            storedParams[6].Value = YS_ZW_FAPIAOKC.I_LINGYONGSL;
            storedParams[7].Value = YS_ZW_FAPIAOKC.S_RUKUR;
            storedParams[8].Value = YS_ZW_FAPIAOKC.D_RUKURQ;
            storedParams[9].Value = YS_ZW_FAPIAOKC.I_TYPE;
            storedParams[10].Value = YS_ZW_FAPIAOKC.S_MIAOSHU;
            storedParams[11].Value = YS_ZW_FAPIAOKC.I_YUANHAODUANID;
            storedParams[12].Value = YS_ZW_FAPIAOKC.ID;
            var result = 0;
            if (Transaction == null)
                result = OracleHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                result = OracleHelper.ExecuteNonQuery(Transaction, CommandType.StoredProcedure, spName, storedParams);
            return result == 0 ? false : true;
        }


        private YS_ZW_FAPIAOKC PopulateYS_ZW_FAPIAOKC(IDataReader dr)
        {
            var YS_ZW_FAPIAOKC = new YS_ZW_FAPIAOKC();
            YS_ZW_FAPIAOKC.ID = dr["ID"] == DBNull.Value ? 0 : (decimal) dr["ID"];
            YS_ZW_FAPIAOKC.S_QISHIHM = dr["S_QISHIHM"] == DBNull.Value ? null : (string) dr["S_QISHIHM"];
            YS_ZW_FAPIAOKC.S_JIESHUHM = dr["S_JIESHUHM"] == DBNull.Value ? null : (string) dr["S_JIESHUHM"];
            YS_ZW_FAPIAOKC.I_SHULIANG = dr["I_SHULIANG"] == DBNull.Value ? null : (decimal?) dr["I_SHULIANG"];
            YS_ZW_FAPIAOKC.S_DANGQIANQSHM = dr["S_DANGQIANQSHM"] == DBNull.Value ? null : (string) dr["S_DANGQIANQSHM"];
            YS_ZW_FAPIAOKC.I_SHENGYUSL = dr["I_SHENGYUSL"] == DBNull.Value ? null : (decimal?) dr["I_SHENGYUSL"];
            YS_ZW_FAPIAOKC.I_JLZT = dr["I_JLZT"] == DBNull.Value ? null : (decimal?) dr["I_JLZT"];
            YS_ZW_FAPIAOKC.I_LINGYONGSL = dr["I_LINGYONGSL"] == DBNull.Value ? null : (decimal?) dr["I_LINGYONGSL"];
            YS_ZW_FAPIAOKC.S_RUKUR = dr["S_RUKUR"] == DBNull.Value ? null : (string) dr["S_RUKUR"];
            YS_ZW_FAPIAOKC.D_RUKURQ = dr["D_RUKURQ"] == DBNull.Value ? null : (DateTime?) dr["D_RUKURQ"];
            YS_ZW_FAPIAOKC.I_TYPE = dr["I_TYPE"] == DBNull.Value ? null : (decimal?) dr["I_TYPE"];
            YS_ZW_FAPIAOKC.S_MIAOSHU = dr["S_MIAOSHU"] == DBNull.Value ? null : (string) dr["S_MIAOSHU"];
            YS_ZW_FAPIAOKC.I_YUANHAODUANID =
                dr["I_YUANHAODUANID"] == DBNull.Value ? null : (decimal?) dr["I_YUANHAODUANID"];
            return YS_ZW_FAPIAOKC;
        }


        private void AddRowNumber(DataTable dt)
        {
            dt.Columns.Add(new DataColumn("RowNumber", typeof(int)));
            for (var i = 0; i < dt.Rows.Count; i++)
                dt.Rows[i][dt.Columns.Count - 1] = i + 1;
        }

        #endregion
    }
}

#endregion